admin.js ➔ instrSavePage   D
last analyzed

Complexity

Conditions 8
Paths 128

Size

Total Lines 116

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
nc 128
nop 0
dl 0
loc 116
rs 4.606
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B admin.js ➔ ... ➔ $.ajax.success 0 27 4

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
function instrSavePage() {
2
3
    // Сохраняем редактор
4
    tinyMCE.triggerSave();
0 ignored issues
show
Bug introduced by
The variable tinyMCE seems to be never declared. If this is a global, consider adding a /** global: tinyMCE */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
5
6
    // Элементы форм
7
    var page_title, page_pid, page_weight, page_hometext, page_footnote, page_status, page_type, page_keywords, page_description, page_dohtml;
8
    // Скрытые элементы форм
9
    var page_token, page_pageid, page_instrid, page_op;
10
11
    // Ссылки на элементы
12
    var var_token = $("#instr_form_page #XOOPS_TOKEN_REQUEST");
13
    var var_pageid = $("#instr_form_page #pageid");
14
    var var_instrid = $("#instr_form_page #instrid");
15
    var var_op = $("#instr_form_page #op");
16
17
    // Название страницы
18
    page_title = $("#instr_form_page #title").val();
19
    // Родительская страница
20
    page_pid = $("#instr_form_page #pid").val();
21
    page_pid = page_pid ? page_pid : 0;
22
    // Вес
23
    page_weight = $("#instr_form_page #weight").val();
24
    // Основной текст
25
    page_hometext = $("#instr_form_page #hometext").val();
26
    // Сноска
27
    page_footnote = $("#instr_form_page #footnote").val();
28
    // Статус
29
    page_status = $('#instr_form_page input:radio[name=status]:checked').val();
30
    page_status = page_status ? page_status : 0;
31
    // Тип
32
    page_type = $("#instr_form_page #type").val();
33
    page_type = page_type ? page_type : 0;
34
    // Мета теги ключевых слов
35
    page_keywords = $("#instr_form_page #keywords").val();
36
    // Мета теги описания
37
    page_description = $("#instr_form_page #description").val();
38
    //
39
    page_dohtml = $('input:checkbox[name=dohtml]:checked').val();
40
    page_dohtml = page_dohtml ? page_dohtml : 0;
41
    //
42
    page_dosmiley = $('input:checkbox[name=dosmiley]:checked').val();
0 ignored issues
show
Bug introduced by
The variable page_dosmiley seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.page_dosmiley.
Loading history...
43
    page_dosmiley = page_dosmiley ? page_dosmiley : 0;
44
    //
45
    page_doxcode = $('input:checkbox[name=doxcode]:checked').val();
0 ignored issues
show
Bug introduced by
The variable page_doxcode seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.page_doxcode.
Loading history...
46
    page_doxcode = page_doxcode ? page_doxcode : 0;
47
    //
48
    page_dobr = $('input:checkbox[name=dobr]:checked').val();
0 ignored issues
show
Bug introduced by
The variable page_dobr seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.page_dobr.
Loading history...
49
    page_dobr = page_dobr ? page_dobr : 0;
50
51
    // Код безопасности
52
    page_token = var_token.val();
53
    // ID страницы
54
    page_pageid = var_pageid.val();
55
    // ID инструкции
56
    page_instrid = var_instrid.val();
57
    // Опция
58
    page_op = var_op.val();
59
60
    // Выполняем AJAX запрос
61
    $.ajax({
62
        url: 'ajax.php',
63
        type: 'post',
64
        // Передаём данные
65
        data: {
66
            title: page_title,
67
            pid: page_pid,
68
            weight: page_weight,
69
            hometext: page_hometext,
70
            footnote: page_footnote,
71
            status: page_status,
72
            type: page_type,
73
            keywords: page_keywords,
74
            description: page_description,
75
            dohtml: page_dohtml,
76
            dosmiley: page_dosmiley,
77
            doxcode: page_doxcode,
78
            dobr: page_dobr,
79
            XOOPS_TOKEN_REQUEST: page_token,
80
            pageid: page_pageid,
81
            instrid: page_instrid,
82
            op: page_op
83
        },
84
        dataType: 'json',
85
        // При успешном выполнении
86
        success: function (json) {
87
88
            // Если передали token
89
            if (json['toket']) {
90
                //
91
                var_token.val(json['toket']);
92
            }
93
            // Если передали pageid
94
            if (json['pageid']) {
95
                //
96
                var_pageid.val(json['pageid']);
97
            }
98
99
            // Очищаем поле сообщений
100
            $('#ins_message').html('');
101
            // Если есть сообщение
102
            if (json['message']) {
103
                // Устанавливаем текст сообщения
104
                //$('#ins_message').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
105
                // Устанавливаем сообщение
106
                $('#ins_message').html(json['message']);
107
                // Показываем сообщение
108
                //$('.success').fadeIn('slow');
109
                // Прокручиваем окно вверх
110
                $('html, body').animate({scrollTop: 0}, 'slow');
111
            }
112
        }
113
    });
114
    //
115
    return false;
116
}
117